package com.example.util.service.impl;

import com.example.util.TempWhiteListUtil;
import com.example.util.mq.disruptor.FileReqData;
import com.example.util.mq.disruptor.service.MsgCommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Map;

@Service("castDefindFileImpl")
@Slf4j
public class FileV1Impl implements MsgCommonService {

    @Override
    public Map doingBusi(FileReqData param) {
        try {
            File file = new File(param.getReadDir());
            File[] files = file.listFiles();
            log.info("文件数量:{}", files.length);
            if (null == files) {
                log.info("文件数量为空");
                return null;
            }
            for (File file2 : files) {
                if (file2.isDirectory()) {
                    log.info("文件夹里包含文件夹，不处理");
                    continue;
                } else {
                    try {
                        TempWhiteListUtil.chooseMobile(file2.getAbsolutePath(), param.getWriteDir(), param.getTerminalManageUrl());
                        continue;
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        continue;
                    }
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return null;
    }
}
